package ihm.panel.camera;

import java.awt.BorderLayout;
import java.util.List;

import ihm.applet.KrakenApplet;
import ihm.panel.KrakenTablePanel;
import ihm.panel.PanelInterface;
import ihm.table.AppletTable;
import ihm.table.AppletTableModel;

import javax.swing.JScrollPane;
import javax.swing.JTable;

import org.hibernate.Session;

import bdd.standalone.bean.Camera;
import bdd.standalone.bean.CameraOptions;

//import bdd.external.bean.Camera;
//import bdd.external.bean.CameraOptions;
//import bdd.external.bean.CameraPlanning;

/**
 * Panneau pour gérer les tâches planifiées associées aux caméras.
 * @author Guillaume Pocas & Jean-Fraçois Augé
 */
public class CameraOptionsPanel extends KrakenTablePanel implements PanelInterface {
	
	private static final long serialVersionUID = 1L;
	private KrakenApplet applet;
	private Camera camera;
	
	private CameraPanel camera_jp;
	
	private static String[] COLUMN_NAMES = {"ID", "Nom", "Type", "Param", "Début", "Fin"};
	private AppletTableModel task_atm;
	private JTable task_jt;
	private Object[][] column_content;
	
	/**
	 * Constructeur.
	 * @param applet
	 * @param cam_jp
	 */
	public CameraOptionsPanel(KrakenApplet applet, CameraPanel cam_jp) {
		this.applet = applet;
		this.camera_jp = cam_jp;
		updateTableInfo();
		initPanel();
	}
	
	@Override
	public void initPanel() {
		this.setLayout(new BorderLayout());
		
		task_atm = new AppletTableModel(COLUMN_NAMES, column_content);
		task_jt = new AppletTable(task_atm);
		task_atm.lockColumn(0);
		task_atm.lockColumn(3);
		task_atm.lockColumn(4);
		task_atm.lockColumn(5);
		
		JScrollPane scrollPane = new JScrollPane(task_jt);
		this.add(scrollPane, BorderLayout.CENTER);
	}
	
	@Override
	public void updateTableInfo() {
		//Session session = applet.getExternalSession();
		Session session = applet.getSession();

		camera = this.camera_jp.getNodePanel().getCurrentCamera();
		@SuppressWarnings("unchecked")
		List<CameraOptions> resultats = session.createCriteria(CameraOptions.class)/*.add(Restrictions.eq("camera", this.camera))*/.list();		
		column_content = new Object[resultats.size()][COLUMN_NAMES.length];
		
		int i;
		for(i = 0; i < resultats.size(); i++) {
			column_content[i][0] = resultats.get(i).getCamopt_id();
			column_content[i][1] = resultats.get(i).getCamopt_name();
			column_content[i][2] = resultats.get(i).getCamopt_type();
			column_content[i][3] = resultats.get(i).getCamopt_param();
			column_content[i][4] = "";//((CameraPlanning) resultats.get(i).getPlannings()).getCamplan_timeBegin();
			column_content[i][5] = "";//((CameraPlanning) resultats.get(i).getPlannings()).getCamplan_timeEnd();
		}
		
		session.close();
	}

	public AppletTableModel getAppletTableModel() { return this.task_atm; }
	public Object[][] getColumnContent() { return this.column_content; }
	
}
